#ifndef _BUOLA_MEDIA_SUPPORT_PULSE_CPULSEMIXER_H_
#define _BUOLA_MEDIA_SUPPORT_PULSE_CPULSEMIXER_H_

#include <buola/media/cmixer.h>
#include "cpulsecontext.h"
#include <pulse/introspect.h>
#include <map>

namespace buola { namespace media { namespace pulse {

class CPulseMixer : public CMixer
{
    struct SSink
    {
        uint32_t mID;
        std::wstring mName;
        int mNumChannels;
        pa_cvolume mVolume;
        bool mMute;
    };
    
public:
    CPulseMixer(CPulseContext &pContext=get_default_context());

    virtual TElement GetElement(const std::wstring &pName);
    
    virtual double GetVolume(TElement,int pChannel=CHANNEL_ALL);
    virtual void SetVolume(TElement,double pValue,int pChannel=CHANNEL_ALL);

    virtual bool GetMute(TElement pElement,int pChannel=CHANNEL_ALL);
    virtual void SetMute(TElement pElement,bool pValue,int pChannel=CHANNEL_ALL);

private:
    CPulseContext &mContext;
    bool mHaveSinkInfo;
    std::map<TElement,SSink> mSinks;
    
    friend void sink_info_cb(pa_context *pCtx,const pa_sink_info *pI,int pEOL,void *pMixer);
    friend void sink_info_update_cb(pa_context *pCtx,const pa_sink_info *pI,int pEOL,void *pMixer);
    friend void subscribe_cb(pa_context *pCtx,const pa_subscription_event_type pEvent,uint32_t pIndex,void *pMixer);
};

/*namespace pulse*/ } /*namespace media*/ } /*namespace buola*/ }

#endif
